package com.QSystem.controller;

import com.QSystem.pojo.Survey;
import com.QSystem.pojo.User;
import com.QSystem.pojo.WholeSurvey;
import com.QSystem.service.SurveyService;
import com.QSystem.service.UserService;
import com.QSystem.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping
public class SurveyController {
    @Autowired
    SurveyService surveyService;
    @Autowired
    UserService userService;

    //创建问卷
    @PostMapping(value = {"/home/create"},produces = {"application/json; charset=UTF-8"})
    public Result register(@RequestBody WholeSurvey wholeSurvey){
        return surveyService.createSurvey(wholeSurvey);
    }

    //根据用户名查询问卷
    @PostMapping(value = {"/home/query"},produces = {"application/json; charset=UTF-8"})
    public Result query(@RequestBody String userName){
        //System.out.println(userName);
        return surveyService.queryAll(userName);

    }

    //根据用户名查询问卷
    @PostMapping(value = {"/home/queryRelease"},produces = {"application/json; charset=UTF-8"})
    public Result queryRelease(@RequestBody String userName){
        //System.out.println(userName);
        return surveyService.queryRelease(userName);

    }

    //根据用户名查询问卷
    @PostMapping(value = {"/home/queryNotRelease"},produces = {"application/json; charset=UTF-8"})
    public Result queryNotRelease(@RequestBody String userName){
        //System.out.println(userName);
        return surveyService.queryNotRelease(userName);

    }


    //修改问卷(先获取对应的问卷)
    @PostMapping(value = {"/home/edit"},produces = {"application/json; charset=UTF-8"})
    public Result edit(@RequestBody Integer surId){
        System.out.println(surId);
        //surveyService.queryById(surId);
        return surveyService.queryById(surId);

    }

    //编辑后保存
    @PostMapping(value = {"/home/save"},produces = {"application/json; charset=UTF-8"})
    public Result save(@RequestBody WholeSurvey wholeSurvey){
        return surveyService.editSurvey(wholeSurvey);
    }

    //删除问卷
    @PostMapping(value = {"/home/del"},produces = {"application/json; charset=UTF-8"})
    public Result del(@RequestBody Integer surId){
        return surveyService.delSurvey(surId);
    }

    @PostMapping(value = {"/home/release"},produces = {"application/json; charset=UTF-8"})
    public Result release(@RequestBody Integer surId){
        //System.out.println(surId);
        return surveyService.releaseSurvey(surId);
    }

    @PostMapping(value = {"/home/cancel"},produces = {"application/json; charset=UTF-8"})
    public Result cancel(@RequestBody Integer surId){
        return surveyService.cancelSurvey(surId);
    }


}
